package com.sample.wanandroidx.ui.test

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import com.luck.picture.lib.PictureSelector
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.listener.OnResultCallbackListener
import com.sample.library.glide.GlideEngine
import com.sample.wanandroidx.R

//https://github.com/LuckSiege/PictureSelector/blob/master/app/src/main/java/com/luck/pictureselector/MainActivity.java
class PictureSelectorActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_picture_selector)
        findViewById<ConstraintLayout>(R.id.constraintLayout).setOnClickListener {
            PictureSelector.create(this).openGallery(PictureMimeType.ofAll()).imageEngine(GlideEngine.createGlideEngine())
                .forResult(object : OnResultCallbackListener<LocalMedia?> {
                    override fun onResult(result: List<LocalMedia?>) {
                        // 结果回调
                        PictureSelector.create(this@PictureSelectorActivity).themeStyle(R.style.picture_WeChat_style)
                            .isNotPreviewDownload(true).imageEngine(GlideEngine.createGlideEngine()) // 请参考Demo GlideEngine.java
                            .openExternalPreview(0, result);
                    }

                    override fun onCancel() {
                        // 取消
                    }
                })
        }
    }
}